package com.yxh.lib_base.ext.xpopup

import android.content.Context
import android.view.View
import android.widget.FrameLayout
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.viewbinding.ViewBinding
import com.lxj.xpopup.core.AttachPopupView
import com.lxj.xpopup.core.BottomPopupView
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.core.DrawerPopupView
import com.lxj.xpopup.impl.FullScreenPopupView
import com.lxj.xpopup.util.XPopupUtils
import com.yxh.lib_base.ext.viewbinding.ViewViewBindingDelegate

/**
 *@创建者：XH-hua
 *@创建时间：2021/5/21 10:42
 *@描述：
 */
abstract class BaseXPopupBottomSheetDBV(mContext: Context) :
    BottomPopupView(mContext) {

    abstract val mBinding: ViewBinding

    override fun addInnerContent() {
        bottomPopupContainer.addView(mBinding.root)
    }

    override fun getPopupWidth(): Int {
        return super.getMaxWidth()
    }
}


abstract class BaseXPopupCenterDBV<DB : ViewDataBinding>(mContext: Context) :
    CenterPopupView(mContext) {

    abstract fun getLayoutId(): Int
    override fun getImplLayoutId(): Int {
        return getLayoutId()
    }

    protected var mBinding: DB? = null

    override fun addInnerContent() {
        super.addInnerContent()
        mBinding = DataBindingUtil.bind(contentView)
    }
}


abstract class BaseXPopupCenterDB(mContext: Context) : CenterPopupView(mContext) {

    override fun getImplLayoutId(): Int {
        return 0
    }

    abstract val mBinding: ViewBinding

    override fun addInnerContent() {
        contentView = mBinding.root
        centerPopupContainer.addView(contentView)
    }
}

abstract class BaseXPopupAttachDB(mContext: Context) : AttachPopupView(mContext) {

    override fun getImplLayoutId(): Int {
        return 0
    }

    abstract val mBinding: ViewBinding

    override fun addInnerContent() {
        attachPopupContainer.addView(mBinding.root)
    }
}

/**
 * 全屏
 */
abstract class BaseXPopupFullScreen(mContext: Context) : FullScreenPopupView(mContext) {
    override fun getImplLayoutId(): Int {
        return 0
    }

    abstract val mBinding: ViewBinding

    override fun addInnerContent() {
        contentView = mBinding.root
        fullPopupContainer.addView(contentView)
    }
}


/**
 * 全屏
 */
abstract class BaseXPopupFullScreenDB(mContext: Context) : CenterPopupView(mContext) {

    override fun getImplLayoutId(): Int {
        return 0
    }

    abstract val mBinding: ViewBinding

    override fun addInnerContent() {
        contentView = mBinding.root
        centerPopupContainer.addView(contentView)
    }

    override fun getMaxHeight(): Int {
        return XPopupUtils.getAppHeight(context)
    }

    override fun getMaxWidth(): Int {
        return XPopupUtils.getAppWidth(context)
    }
}


/**
 *
 */
abstract class BaseXPopupDrawerVB(context: Context) : DrawerPopupView(context) {
    abstract val mBinding: ViewBinding
    override fun addInnerContent() {
        drawerContentContainer.addView(mBinding.root)
    }

    inline fun <reified T : ViewBinding> View.viewBinding() =
        ViewViewBindingDelegate(T::class.java, this, false, `access$drawerContentContainer`)

    @PublishedApi
    internal var `access$drawerContentContainer`: FrameLayout?
        get() = drawerContentContainer
        set(value) {
            drawerContentContainer = value
        }
}
